using System;
using System.Linq;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Collections.Generic;
using Acme.Sales.EFDAL.Entity;

namespace Acme.Sales.EFDAL
{
	#region SalesEntitiesExtensions

	/// <summary>
	/// Extension methods for this library
	/// </summary>
	public static partial class SalesEntitiesExtensions
	{
		#region Include Extension Methods

		/// <summary>
		/// Specifies the related objects to include in the query results.
		/// </summary>
		/// <param name="item"></param>
		/// <param name="entity">The related entity type to include</param>
		public static ObjectQuery<Acme.Sales.EFDAL.Entity.Customer> Include(this ObjectQuery<Acme.Sales.EFDAL.Entity.Customer> item, TableMappingConstants entity)
		{
			return item.Include(GetEntityMap(entity));
		}

		/// <summary>
		/// Specifies the related objects to include in the query results.
		/// </summary>
		/// <param name="item"></param>
		/// <param name="entity">The related entity type to include</param>
		public static ObjectQuery<Acme.Sales.EFDAL.Entity.Employee> Include(this ObjectQuery<Acme.Sales.EFDAL.Entity.Employee> item, TableMappingConstants entity)
		{
			return item.Include(GetEntityMap(entity));
		}

		/// <summary>
		/// Specifies the related objects to include in the query results.
		/// </summary>
		/// <param name="item"></param>
		/// <param name="entity">The related entity type to include</param>
		public static ObjectQuery<Acme.Sales.EFDAL.Entity.Region> Include(this ObjectQuery<Acme.Sales.EFDAL.Entity.Region> item, TableMappingConstants entity)
		{
			return item.Include(GetEntityMap(entity));
		}

		/// <summary>
		/// Specifies the related objects to include in the query results.
		/// </summary>
		/// <param name="item"></param>
		/// <param name="entity">The related entity type to include</param>
		public static ObjectQuery<Acme.Sales.EFDAL.Entity.SystemUser> Include(this ObjectQuery<Acme.Sales.EFDAL.Entity.SystemUser> item, TableMappingConstants entity)
		{
			return item.Include(GetEntityMap(entity));
		}

		/// <summary>
		/// Specifies the related objects to include in the query results.
		/// </summary>
		/// <param name="item"></param>
		/// <param name="entity">The related entity type to include</param>
		public static ObjectQuery<Acme.Sales.EFDAL.Entity.Territory> Include(this ObjectQuery<Acme.Sales.EFDAL.Entity.Territory> item, TableMappingConstants entity)
		{
			return item.Include(GetEntityMap(entity));
		}

		#endregion

		private static string GetEntityMap(TableMappingConstants entity)
		{
			switch (entity)
			{
				case TableMappingConstants.Customer: return "Customer";
				case TableMappingConstants.Employee: return "Employee";
				case TableMappingConstants.EmployeeType: return "EmployeeType";
				case TableMappingConstants.Region: return "Region";
				case TableMappingConstants.SystemUser: return "SystemUser";
				case TableMappingConstants.Territory: return "Territory";
				default: throw new Exception("Unknown entity type: " + entity.ToString());
			}
		}

	}

	#endregion

}
